//
//  FinishedCell.m
//  Everest
//
//  Created by 李其昌 on 15/1/2.
//  Copyright (c) 2015年 ThreeL. All rights reserved.
//

#import "FinishedCell.h"
#import "FileModel.h"
#import "NewDownloadViewController.h"
#import "FilesDownManage.h"
#import "PlayViewController.h"
#import "AvReadioPlayer.h"

@implementation FinishedCell

- (void)dealloc
{
    [_deleteButton release];
    [_playButton release];
    [_timeLable release];
    [_fileSize release];
    [_fileName release];
    [_fileImage release];
    [_fileType release];
    [_fileInfo release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 文件名
        self.fileName = [[UILabel alloc] init];
        self.fileName.text = @"音频名";
        self.fileName.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.fileName];
        [_fileName release];
        // 文件总大小
        self.fileSize = [[UILabel alloc] init];
        self.fileSize.text = @"大小:1024.00k";
        self.fileSize.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.fileSize];
        [_fileSize release];
        // 文件图片
        self.fileImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.fileImage];
        [_fileImage release];
        
        // 文件类型
        self.fileType = [[UILabel alloc] init];
        self.fileType.text = @"格式:aac";
        self.fileType.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.fileType];
        [_fileType release];
        // 时间
        self.timeLable = [[UILabel alloc] init];
        self.timeLable.text = @"大小:1024.00k";
        self.timeLable.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.timeLable];
        [_timeLable release];
        // 删除按钮
        self.deleteButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        [self.contentView addSubview:self.deleteButton];
        [self.deleteButton addTarget:self action:@selector(deleteFile:) forControlEvents:UIControlEventTouchUpInside];
        
        // 操作按钮
        self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"下载管理-开始按钮.png"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.playButton];
    }
    return self;
}

- (void)layoutSubviews
{
    self.fileName.frame = CGRectMake(kCellWidth / 10 * 3, self.contentView.frame.size.height * 0.0625, kCellWidth / 2, self.contentView.frame.size.height * 0.375);
    self.fileType.frame = CGRectMake(kCellWidth / 10 * 3, self.contentView.frame.size.height * 0.444, kCellWidth * 0.2, self.contentView.frame.size.height * 0.2);
    self.fileSize.frame = CGRectMake(kCellWidth / 10 * 3 + kCellWidth * 0.2, self.contentView.frame.size.height * 0.444, kCellWidth * 0.3, self.contentView.frame.size.height * 0.2);
    self.timeLable.frame = CGRectMake(kCellWidth / 10 * 3, self.contentView.frame.size.height * 0.74, kCellWidth * 0.51, self.contentView.frame.size.height * 0.26);
    self.fileImage.frame = CGRectMake(kCellWidth * 0.01, self.contentView.frame.size.height * 0.06, kCellWidth * 0.26, self.contentView.frame.size.height * 0.87);
    self.playButton.frame = CGRectMake(kCellWidth * 0.01, self.contentView.frame.size.height * 0.06, kCellWidth * 0.26, self.contentView.frame.size.height * 0.87);
    self.deleteButton.frame = CGRectMake(kCellWidth * 0.86, self.contentView.frame.size.height * 0.26, kCellWidth * 0.1, self.contentView.frame.size.height * 0.52);
    
}



- (void)deleteFile:(UIButton *)button
{
    [[FilesDownManage sharedFilesDownManage]  deleteFinishFile:self.fileInfo];
    if ([self.delegate respondsToSelector:@selector(deleteFinishedFile:)]) {
        [(NewDownloadViewController *)self.delegate deleteFinishedFile:self.fileInfo];
    }
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
